﻿using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class LS_CLRYQKModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(1 - DateTime.Now.Day).ToString("yyyy-MM-dd 00:00:00");
            this.EndDate.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();

        }

        protected void BindReportDataSource()
        {

            DateTime start = Convert.ToDateTime(this.StartDate.Text);
            DateTime end = Convert.ToDateTime(this.EndDate.Text);
            string centerID = (this.centerID.Text).ToString();
            string stationID = (this.stationID.Text).ToString();
            string actualCode = (this.actualCode.Text).ToString();
            string ambulanceNumber = (this.ambulanceNumber.Text).ToString();
            string start1 = start.ToString();
            string end1 = end.ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            //Microsoft.Reporting.WebForms.ReportParameter ac = new Microsoft.Reporting.WebForms.ReportParameter("ActualCode", actualCode);

            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });

            LSDAL dal = new LSDAL();
            switch (reportName)
            {
                case "LS_CLRYQK.rdlc":
                    this.Page.Title = "车辆燃油情况表";
                    DataTable dt1 = dal.Get_CLRYQK(start, end, centerID, stationID, actualCode, ambulanceNumber);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_CLRYQK", dt1));
                    break;
                case "TJ_CLYHQKHZ.rdlc":
                    this.Page.Title = "车辆耗油情况汇总表";
                    DataTable dt2 = dal.Get_CLYHQKHZ(start, end, centerID, stationID, actualCode, ambulanceNumber);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_CLYHHZ", dt2));
                    break;            
                default:
                    break;
            }
            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}